package com.example.canvastest;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by 700 on 2018/7/31.
 */

public class DrawText_DrawPosText extends View{

    private Paint mTextPaint;
    private float[] offset = new float[10];

    public DrawText_DrawPosText(Context context, AttributeSet attrs,
                        int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DrawText_DrawPosText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawText_DrawPosText(Context context) {
        super(context);
    }

    private void initView(){
        for(int i = 0; i<10; i+=2){
            offset[i] = 100;
            offset[i+1] = 250+150*i/2;
        }
        mTextPaint = new Paint();
        mTextPaint.setColor(getResources().getColor(
                android.R.color.holo_blue_light
        ));
        mTextPaint.setTextSize(50);//设置文字大小
//        mTextPaint.setTextAlign(Paint.Align.CENTER);//设置居中
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        initView();
        canvas.drawText("hehehehehedadadadadadadada",100,100,mTextPaint);
        canvas.drawPosText("hehed",offset,mTextPaint);

    }
}
